import { addComDao, delComDao, getComByIdsByPageDao, getComByPageDao, updateComDao } from "../Dao/commentDao.js";
import { findUserByIdDao } from "../Dao/userDao.js";

export const addComServ = async (obj) => {
    await addComDao();
    return {
        code: 0,
        msg: 'add OK'
    }
}

export const delComServ = async (id) => {
    await delComDao(id)
    return {
        code: 0,
        msg: "del ok"
    }
}

export const updateComServ = async(id,obj) => {
    await updateComDao(id,obj)
    return {
        code:0,
        msg:"update ok"
    }
}

export const getComByPageServ = async (pageXOffset,size) => {
    const data = await getComByPageDao(pageXOffset,size);
    data.list = await Promise.all(data.list.map(async item =>{
        const obj = item.toObject()
        obj.user = await findUserByIdDao(obj.userId)
        return obj
    }))
    return{
        code: 0,
        data
    }
}
export const getComByIdsPageServ = async (ids,pageXOffset,size)=>{
    const data = await getComByIdsByPageDao(ids,pageXOffset,size);
    data.list = await Promise.all(data.list.map(async item=>{
        const obj = item.toObject();
        obj.user = await findUserByIdDao(obj.userId)
        return obj
    }))
    return {
        code: 0,
        data
    }
}